package com.ssi.core.config;


import java.util.Properties;

import com.ssi.core.utils.spring.SpringContextHolder;

/**
 * 类说明：该类用于加载SIS平台运行时配置信息的持有者，是一个助手类用于方便的得到配置文件中每一个属性的值
 * @创建时间 Jan 8, 2011 4:01:31 PM
 * @创建人： Farley
 * @邮箱：kfy0521@163.com
 */
public class ConfigHolder {
	private static FrameworkConfig config ;
	private static final int PAGE_SIZE = 80;
	private static final int PAGE_MAXRECORDS=0;
	private static final boolean RELOAD = false;
	
	public static Properties getProperties(){
		if(config == null)
			config = (FrameworkConfig)SpringContextHolder.getBean("sisConfig");
		return config.getConfig();
	}
	
	public static String getProperty(String key){
		return getProperties().getProperty(key);
	}
	
	public static boolean getFrameworkConfigReload(){
		
		String reload = getProperties().getProperty("sis.config.reload");
		if(reload == null)
			return false;
		
		return Boolean.parseBoolean(reload);
	}
	
	private static void ObjectNull(){
		if(getFrameworkConfigReload())
			config = null;
	}
	
	/**
	 * 缺省列表页面一页的记录个数
	 * @return 返回缺省列表页面一页的记录个数
	 */
	public static int getPageSize(){
		String pageSize = getProperties().getProperty("sis.pageinfo.pagesize");
		if(pageSize == null)
			return PAGE_SIZE;
		ObjectNull();
		return Integer.parseInt(pageSize);
	}
	
	/**
	 * 缺省列表页最大限记录数的值,0为不受限制
	 * @return 列表页最大限记录数
	 */
	public static int getMaxRecords(){
		String maxRecords = getProperties().getProperty("sis.pageinfo.maxrecords");
		if(maxRecords == null)
			return PAGE_MAXRECORDS;
		ObjectNull();
		return Integer.parseInt(maxRecords);
	}
	
	
	/**
	 * 是否发布完成
	 * @return
	 */
	public static boolean getPublished(){
		String published = getProperties().getProperty("sis.depolyment.published");
		ObjectNull();
		if(published == null || published.trim().equals(""))
			return false;
		return Boolean.parseBoolean(published);
	}
	
	public static String getRootUpload(){
		String upload = getProperties().getProperty("sis.depolyment.rootupload");
		ObjectNull();
		if(upload == null || upload.trim().equals(""))
			return "upload";
		return upload;
	}
	
	
	
	public static String getMaxLimit() {
		String maxCode = getProperties().getProperty("sis.pageinfo.maxlimitrecode");
		ObjectNull();
		if(maxCode == null || maxCode.trim().equals(""))
			return "100000";
		return maxCode;
	}
	
	
}
